<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="cn.estore.entity.Product" %>
<%@ page import="cn.estore.dao.ProductDao" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>按产地查询商品信息展示</title>
	<style>
		body {
			font-family: Arial, sans-serif;
			background-color: #f8f9fa;
			margin: 0;
			padding: 0;
			text-align: center;
		}

		header {
			background-color: #343a40;
			color: white;
			padding: 20px 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-left: 20px;
			padding-right: 20px;
		}

		header a {
			color: white;
			text-decoration: none;
			margin: 0 15px;
		}

		main {
			padding: 20px;
		}

		table {
			width: 80%;
			margin: 20px auto;
			border-collapse: collapse;
			box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
		}

		th, td {
			padding: 15px;
			text-align: left;
			border-bottom: 1px solid #ddd;
		}

		img {
			max-width: 100%;
			max-height: 150px;
			display: block;
			margin: 0 auto;
		}

		.product-info {
			padding-left: 20px;
		}
	</style>
</head>
<body>
<header>
	<a href="login.jsp">登录</a>
	<a href="zhuce.jsp">注册</a>
</header>
<main>
	<%
		request.setCharacterEncoding("UTF-8");
		// 获取用户输入的产地参数
		String producingArea = request.getParameter("producingArea");
		// 简单校验参数是否为空，如果为空给出提示信息并停止后续操作
		if (producingArea == null || producingArea.trim().isEmpty()) {
			out.println("<p>请输入有效的产地信息进行查询。</p>");
			return;
		}

		ProductDao dao = new ProductDao();
		List<Product> ProductList = null;
		try {
			// 调用数据库查询方法获取对应产地的商品列表
			ProductList = dao.selectProductsByArea(producingArea);
		} catch (SQLException e) {
			// 捕获数据库操作异常，输出提示信息告知用户
			out.println("数据库查询出现异常，请稍后再试！");
			e.printStackTrace();
		}

		if (ProductList!= null &&!ProductList.isEmpty()) {
			for (Product e : ProductList) {
	%>
	<table border="1" align="center">
		<tr>
			<td width="40%">
				<img src="<%="productImages/" + e.getPicture()%>" alt="商品图片">
			</td>
			<td class="product-info">
				<div>商品：<%=e.getName()%></div>
				<div>价格：<%=e.getMarketPrice()%>元</div>
				<div>简介：<%=e.getDescription()%></div>
				<div>登录才能购买</div>
			</td>
		</tr>
	</table>
	<%
			}
		} else {
			out.println("<p>未查询到产地为 " + producingArea + " 的商品信息。</p>");
		}
	%>
</main>
</body>
</html>
